<?php 
class giaovienAdmin extends CI_Controller
{
	function danhsachgv()
	{
		$data = array( 
			'dsgv'=>$this->mgiaovien->danhsachgv(),
			'page'=>'danhsachgiaovien'
		);
		$this->load->view('admin/templateadmin', $data);
	}
	
	function xoagiaovien($magv)
	{
		$this->mgiaovien->xoagv($magv);
		redirect('admin/giaovienadmin/danhsachgv');	
	}
	
	function thongtingiaovien($magv)
	{
		$data = array(
			'page'=>'thongtingiaovien',
			'ttgv'=>$this->mgiaovien->thongtingiaovien($magv)
		);
		$this->load->view('admin/templateadmin', $data);
	}
	
	function capnhatgiaovien($magv)
	{
		$data = array('cngv'=>$this->mgiaovien->thongtingiaovien($magv),'page'=>'capnhatgiaovien');
		$this->load->view('admin/templateadmin',$data);
	}
	
	function xulycapnhat()
	{
		$magv = $this->input->post('magv');
		$tengv = $this->input->post('tengv');
		$ngaysinh = $this->input->post('ngaysinh');
		$mota = $this->input->post('mota');
		$hienthi = $this->input->post('hienthi')=='true' ? 'true' : 'false';
		
		//cap nhat hinh anh
		$config['upload_path'] = './asset/upload/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size']	= '1024';
		$config['encrypt_name']	= true;
		$this->load->library('upload', $config);
		$hinh = '';
		if($this->upload->do_upload('hinh'))
		{
			$df = array('upload_data' => $this->upload->data());
			$hinh = $df['upload_data']['file_name'];
		}
		if ($hinh == '')
			$hinh = $this->input->post('oldhinh');
			
		$this->mgiaovien->capnhatgv($magv, $tengv, $ngaysinh, $hinh, $mota, $hienthi);
		redirect('admin/giaovienadmin/danhsachgv');
	}
	
	function themgiaovien()
	{
		$data = array(
			'page'=>'themgiaovien'
			
		);
		$this->load->view('admin/templateadmin', $data);
	}
	
	function xulythem()
	{
		$tengv = $this->input->post('tengv');
		$ngaysinh = $this->input->post('ngaysinh');
		$mota = $this->input->post('mota');
		
		// Thuc hien upload hinh anh
		$config['upload_path'] = './asset/upload/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size']	= '1024';
		$config['encrypt_name']	= true;
		$this->load->library('upload', $config);
		$hinh = '';
		if($this->upload->do_upload('hinh'))
		{
			$df = array('upload_data' => $this->upload->data());
			$hinh = $df['upload_data']['file_name'];
		}
		
		$hienthi = $this->input->post('hienthi')=='true' ? 'true' : 'false';
		$this->mgiaovien->themgv($tengv, $ngaysinh, $hinh, $mota, $hienthi);
		redirect('admin/giaovienAdmin/danhsachgv');		
	}
}


?>